﻿using DoNet.Common.Helpers;
using DoNet.Core;
using DoNet.System.Dtos;
using DoNet.System.Models;

namespace DoNet.System.IServices
{
    public interface ITokenService : IService<Token, TokenOutputDto>
    {
        #region 同步方法
        /// <summary>
        /// 同步获取当前AppId未过期的Token
        /// </summary>
        /// <param name="appId"></param>
        /// <returns></returns>
        Token GetTokenByAppId(string appId);
        /// <summary>
        /// 同步获取当前token或者刷新token
        /// </summary>
        /// <param name="token">当前token或者刷新token</param>
        /// <returns></returns>
        Token GetTokenIsRevoked(string token);
        /// <summary>
        /// 同步根据刷新token获取当前token
        /// </summary>
        /// <param name="refreshToken">刷新token</param>
        /// <returns></returns>
        Token GetTokenByRefreshToken(string refreshToken);
        /// <summary>
        /// 同步获取token
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="appSecret"></param>
        /// <param name="accessExpire"></param>
        /// <param name="refreshExpire"></param>
        /// <param name="claims"></param>
        /// <param name="creatorUserId"></param>
        /// <param name="creatorTime"></param>
        /// <returns></returns>
        AccessTokenOut? GetTokenPair(string appId, string appSecret, int accessExpire, int refreshExpire, Dictionary<string, string> claims, long creatorUserId, DateTime creatorTime);
        /// <summary>
        /// 同步验证token
        /// </summary>
        /// <param name="token"></param>
        /// <returns>true 有效的(刷新)令牌；false 无效的(刷新)令牌</returns>
        bool ValidateToken(string token);
        /// <summary>
        /// 同步通过RefreshToken获取旧Token
        /// </summary>
        /// <param name="refreshToken"></param>
        /// <param name="accessExpire"></param>
        /// <returns></returns>
        RefreshTokenOut? ForceRefresh(string refreshToken, int accessExpire, long lastModifyUserId, DateTime lastModifyTime);
        #endregion 同步方法
        #region 异步方法
        /// <summary>
        /// 异步获取当前AppId未过期的Token
        /// </summary>
        /// <param name="appId"></param>
        /// <returns></returns>
        Task<Token> GetTokenByAppIdAsync(string appId);
        /// <summary>
        /// 异步获取当前token或者刷新token
        /// </summary>
        /// <param name="token">当前token或者刷新token</param>
        /// <returns></returns>
        Task<Token> GetTokenIsRevokedAsync(string token);
        /// <summary>
        /// 异步根据刷新token获取当前token
        /// </summary>
        /// <param name="refreshToken">刷新token</param>
        /// <returns></returns>
        Task<Token> GetTokenByRefreshTokenAsync(string refreshToken);
        /// <summary>
        /// 异步获取token
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="appSecret"></param>
        /// <param name="accessExpire"></param>
        /// <param name="refreshExpire"></param>
        /// <param name="claims"></param>
        /// <param name="creatorUserId"></param>
        /// <param name="creatorTime"></param>
        /// <returns></returns>
        Task<AccessTokenOut?> GetTokenPairAsync(string appId, string appSecret, int accessExpire, int refreshExpire, Dictionary<string, string> claims, long creatorUserId, DateTime creatorTime);
        /// <summary>
        /// 异步验证token
        /// </summary>
        /// <param name="token"></param>
        /// <returns>true 有效的(刷新)令牌；false 无效的(刷新)令牌</returns>
        Task<bool> ValidateTokenAsync(string token);
        /// <summary>
        /// 异步通过RefreshToken获取旧Token
        /// </summary>
        /// <param name="refreshToken"></param>
        /// <param name="accessExpire"></param>
        /// <returns></returns>
        Task<RefreshTokenOut?> ForceRefreshAsync(string refreshToken, int accessExpire, long lastModifyUserId, DateTime lastModifyTime);
        #endregion 异步方法
    }
}
